<?php	
	// Interface function	
	function oh_module_p($tokens) {	
		global $oh_object_p;
		if (count($tokens)>0) {
			$p = $oh_object_p->this();
			if ($tokens[0] == $p[1]) {
				return true;
			} else {
				return false;
			}
		}	
		return $oh_object_p;
	} 		

	// Option file required
	//require_once($oh['path']."/modules/pagemanage/pagemanage.class.php");
		
	// Main class of module
	class oh_class_p {
		public $rules;
		function oh_class_p() {
			$this->rules = array(
			
			);
		}
		function add_rules($rules) {
			$rules = explode(";",$rules);
			foreach($rules as $n => $r) {				
				$rule = array();
				$r = trim($r);
				if (strlen($r)>3) {
					if (false) {
					} else if ($r{0} == "!") {
						$rule['func'] = "NOT";
						$r = substr($r,1);
					} else if ($r{0} == "&") {
						$rule['func'] = "REF";
						$r = substr($r,1);
					} else if ($r{0} == "%") {
						$rule['func'] = "CALL";
						$r = substr($r,1);
					} else {
						$rule['func'] = "OPEN";					
					}
					if (strpos($r,"=") > 0) {
						$r = explode("=",$r);
						$rule["div"] = "HAVE";					
					} else {				
						$r = explode(">",$r);				
						$rule["div"] = "TO";
					}
					$r[] = "home";
					$rule['left'] = trim($r[0]);
					$right = explode(",",$r[1]);
					$rule["right"] = array();
					foreach($right as $right0) {
						$rule["right"][] = trim($right0);
					}
					$this->rules[] = $rule;
				}
			}			
		}
		function get_TURL() {
			$u = $_SERVER["REQUEST_URI"];
			if (strpos($u,"?") !== FALSE) {
			//	echo substr($u,0,strpos($u,"?"));
				$e = substr($u,0,strpos($u,"?"));
			} else {
			//	echo $u;
				$e = $u;
			}
			//echo '<br>';
			//echo dirname($_SERVER["SCRIPT_NAME"]);	
			$d = dirname($_SERVER["SCRIPT_NAME"]);	
			//echo '<br>';
			$r = substr($e,strlen($d));
			$r = explode("/",$r);
			$TGET = $_GET;
			$TURL = $_GET;
			foreach($r as $t) {
				if (strlen($t)>0) {
					$TURL[] = $t;
				}
			}
			return $TURL;
		} 
		function this() {
			$o = array("home");
			$t = $this->get_TURL();			
			foreach($this->rules as $n=>$rule) {
				if ($rule['func'] == "REF") {
					if (isset($o[$rule['left']])) {
						$o[$rule['left']] = $rule['right'][0];
					}
					if ($o[count($o)-1] == $rule['left']) {
						$o[count($o)-1] = $rule['right'][0];
					}
				}
				if ($rule['func'] == "OPEN") {
					if (isset($t[$rule['left']])) {
						if (in_array($t[$rule['left']],$rule['right'])) {
							$o[] = $t[$rule['left']];
						} else {
							$o[] = $rule['left'];
						}
					}
				}
			}		
			return $o;
		}
		function light_this() {
			if (isset($_GET["page"])) {
				if (isset($_GET[$_GET["page"]])) {
					return array(
						"index",
						strtolower($_GET["page"]),
						strtolower($_GET[$_GET["page"]]),
					);						
				} else {				
					return array(
						"index",
						strtolower($_GET["page"]),
					);	
				}
			} else {
				return array("index");
			}		
		}
	}
	
	// Main object of module
	global $oh_object_p;
	$oh_object_p = new oh_class_p();
?>
